<template>
    <section>
        <span class="primary my-2 w-full text-center" style="font-size: 14px; display: inline-block">
            <span class="danger">*</span>
            该界面功能：对攻击山东数据库的国家进行统计
        </span>
        <avue-crud :option="option"
                   :table-loading="loading"
                   :data="data"
                   :page.sync="page"
                   v-model="form"
                   :search.sync="query"
                   ref="crud"
                   @search-change="searchChange"
                   @search-reset="searchReset"
                   @current-change="currentChange"
                   @size-change="sizeChange"
                   @refresh-change="refreshChange"
                   @on-load="onLoad">
            <template slot="menuLeft">
                <excel-export v-bind="excelExportProps">
                </excel-export>
            </template>
        </avue-crud>
    </section>
</template>

<script>
  import {dateFormat} from "../../../../util/date";
  import {getAttackSdDbCountry} from "@/youan/api/sd_city_db_attacked_analysis/sdCityDbAttackedAnalysis";
  import excelExport from "@/youan/components/excel/excel-export";

  export default {
    name: "attackSdDbCountry",
    data() {
      return {
        form: {},
        query: {
          date: dateFormat(new Date(), "yyyy-MM-dd")
        },
        excelExportProps: {
          exportUrl: "/api/sd_city_db_attacked_analysis/exportAttackSdDbCountryExcel",
          prepareQuery: this.prepareQuery,
          loadingText: "",
          excelName: "对山东数据库发起攻击国家统计"
        },
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        option: {
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: false,
          delBtn: false,
          editBtn: false,
          addBtn: false,
          menu: false,
          dialogType: "drawer",
          dialogClickModal: false,
          emptyBtn: false,
          column: [
            {
              label: "发起攻击国家",
              prop: "attackCountry",
            },
            {
              label: "截至日期累计发起攻击次数",
              prop: "attackedTotalCount",
            },
            {
              label: "日期",
              prop: "date",
              type: "date",
              valueFormat: "yyyy-MM-dd",
              hide: true,
              search: true,
              searchRules: [
                {
                  required: true,
                  message: "请选择日期",
                  trigger: "change"
                }
              ]
            },
          ]
        },
        data: []
      };
    },
    methods: {
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      currentChange(currentPage) {
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getAttackSdDbCountry(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
        });
      },
    },
    activated() {
      this.$nextTick(() => {
        if (this.$refs.crud.$refs.table) {
          this.$refs.crud.$refs.table.doLayout();
        }
      })
    },
    components: {
      excelExport
    }
  }
</script>

<style scoped>

</style>